home *** CD-ROM | disk | FTP | other *** search
- // getreg.c
- // Function to get the user out of the keyfile
- // Must return zero otherwise something is wrong
-
- #include <fcntl.h>
- #include <exec/types.h>
- #include <exec/exec.h>
- #include <string.h>
- #include <stdio.h>
-
- int GetRegisteredUser(char *filename, char *user)
- {
-
- int h;
- int i;
- unsigned char x;
- int cs;
- int l;
-
- h=open(filename,O_RDONLY);
- if(h<0)
- return(-1);
-
- cs=0;
- for(i=0;i<200;i++)
- {
- read(h,&x,1);
- cs=cs+x;
- }
-
- read(h,&x,1);
- cs=cs%256;
- if(x!=cs)
- {
- close(h);
- return(-1);
- }
-
- read(h,&x,1);
- l=x;
-
- cs=0;
- for(i=0;i<l;i++)
- {
- read(h,&x,1);
- cs=cs+x;
- user[i]=x-85-i;
- }
-
- user[l]=0;
- read(h,&x,1);
- cs=cs%256;
- if(cs!=x)
- {
- close(h);
- return(-3);
- }
-
- cs=0;
- for(i=0;i<200;i++)
- {
- read(h,&x,1);
- cs=cs+x;
- }
-
- read(h,&x,1);
- cs=cs%256;
- if(x!=cs)
- {
- close(h);
- return(-2);
- }
-
- close(h);
- return(0);
- }
- // The End
-